//
//  ASTabbar.swift
//  weiboBlog
//
//  Created by asenter on 16/3/26.
//  Copyright © 2016年 asenter. All rights reserved.
//

import UIKit

let tabBarItemCount = 5

class ASTabbar: UITabBar {

    //对底部按钮进行布局
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        print("aidesi")
        
        let width = frame.width / CGFloat(tabBarItemCount)
        
        let originFrame = CGRect(x: 0, y: 0, width: width, height: frame.height)
        
        var index = 0
        
        for view in subviews {
            
            let clos = NSClassFromString("UITabBarButton")
            
            if view.isKindOfClass(clos!){
                
                view.frame = CGRectOffset(originFrame, CGFloat(index)*width, 0)
                
                index += index == 1 ? 2 : 1
                
            }
            
        }
        
        composeButton.frame = CGRectMake(2*width, 0, width, frame.height)
        
        
        
    }
    
    private lazy var composeButton: UIButton = {
        
        let button = UIButton()
        
        //设置按钮图片
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_heighted"), forState: UIControlState.Highlighted)
        
        //添加按钮图片
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        self.addSubview(button)
        
        return button
    }()

}
